package org.example.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//direct直连模式的交换机配置,包括一个direct交换机，两个队列，三根网线binding


@Configuration
public class DirectExchangeConfig {


    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct");
    }

    @Bean
    public Queue myDirectQueue1(){
        return new Queue("myDirectQueue1");
    }

    @Bean
    public Queue myDirectQueue2(){
        return new Queue("myDirectQueue2");
    }

    @Bean
    public Queue myDirectQueue3(){
        return new Queue("myDirectQueue3");
    }


    //3个binding将交换机和相应队列连起来
    @Bean
    public Binding bindingorange(){
        Binding binding= BindingBuilder.bind(myDirectQueue1()).to(directExchange()).with("orange");
        return binding;
    }

    @Bean
    public Binding bindingblack(){
        Binding binding=BindingBuilder.bind(myDirectQueue2()).to(directExchange()).with("black");
        return binding;
    }

    @Bean
    public Binding bindinggreen(){
        Binding binding=BindingBuilder.bind(myDirectQueue3()).to(directExchange()).with("green");
        return binding;
    }


}
